{if !$isLoadScript}
	<link type="text/css" rel="stylesheet" href="__STATIC__/webuploader/css/webuploader.css">
	<script type="text/javascript" charset="utf-8" src="__STATIC__/webuploader/js/webuploader.js"></script>
{/if}
<div class="controls">
	<div id="uploader_{$id}" style="padding-bottom: 5px;">{:lang('select files')}</div><!-- 上传按钮 -->
	<input type="hidden" name="{$id}" value="{$value}" id="file_upload_{$id}">
	<div id="file_list_{$id}">
		{notempty name="files"}
		    {volist name="files" id="vo"}
		        <div>
			        {$vo.name}
			        <a onclick="del_file_{$id}(this, {$vo.id})"><i class="icon-trash"></i></a>
		        </div>
		    {/volist}
	    {/notempty}
	</div>
</div>
<script type="text/javascript">
    var id = "#uploader_{$id}";
    var $list_{$id}=$('#file_list_{$id}');
    var uploader_{$id} = WebUploader.create({
        swf: '__STATIC__/webuploader/js/uploader.swf',
        server: "{:url('core/File/uploadFile')}",
        pick: id,
        resize: false
    });

    uploader_{$id}.on('fileQueued', function(file) { // 上传队列
        uploader_{$id}.upload();

        toast.showLoading();
    });
    uploader_{$id}.on('uploadSuccess', function(file, ret) { // 上传成功 file[name,id]
        if ( ret.status==1 ) {
            toast.success("{:lang('upload success')}");

            $list_{$id}.append('<div>'+ret.data.file.name+' <a onclick="del_file_{$id}'+'(this, '+ret.data.file.id+')"><i class="icon-trash"></i></a></div>');
            upAttachVal($('#file_upload_{$id}'), 'add', ret.data.file.id);
        } else {
            toast.error("{:lang('upload fail')}"+ret.info);
        }
    });
    uploader_{$id}.on('uploadError', function(file) {
    	toast.error("{:lang('upload fail')}");
    });
    uploader_{$id}.on('uploadComplete', function(file) {
  		toast.hideLoading();
    });

    function upAttachVal(input, type, attachId) {
        var $attach_ids = input;
        var attachVal = $attach_ids.val();
        var attachArr = attachVal.split(',');
        var newArr = [];

        for ( var i in attachArr ) {
            if ( attachArr[i] !== '' && attachArr[i] !== attachId.toString() ) newArr.push(attachArr[i]);
        }
        type === 'add' && newArr.push(attachId);
        $attach_ids.val(newArr.join(','));
    }
    function del_file_{$id}(obj, attachId) {
        upAttachVal($('#file_upload_{$id}'), 'del', attachId);
        $(obj).parent('div').remove();
    }
</script>